<template>
  <div id="tmpl">
    <!--1.0 图片分类-->
    <div id='cate'>
      <ul v-bind="{style:'width:'+ulWidth+'px'}">
        <li @click="getimages(0)">全部</li>
        <li v-for="(item,index) in cates" @click="getimages(item.id)" :key='index'>{{item.title}}</li>
      </ul>
    </div>
    <div id="imglist">
      <ul>
        <li v-for="(item,index) in imgslist">
          <router-link v-bind="{to:'/photo/photoinfo/'+item.id}">
            <img v-lazy="item.img_url">
            <div id="desc">
              <h5 v-text="item.title"></h5>
              <p v-text="item.zhaiyao"></p>
            </div>
          </router-link>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import { Lazyload } from 'mint-ui';
export default {
  data() {
    return {
      cates: [],
      imgslist: [],
      ulWidth: 0
    };
  },
  created() {
    this.getlisttitle();
    this.getlistimg();
  },
  methods: {
    getlisttitle() {
      var url = this.$common.apidomain + '/api/getimgcategory';
      this.$http.get(url).then(function (res) {
        this.cates = res.body.message;
        this.ulWidth = 62 * (this.cates.length + 1);
      })
    },
    getlistimg() {
      var url = this.$common.apidomain + '/api/getimages/0';
      this.$http.get(url).then(function (res) {
        this.imgslist = res.body.message;
      })
    },
    getimages(id) {
      var url = this.$common.apidomain + '/api/getimages/'+id;
      this.$http.get(url).then(function (res) {
        this.imgslist = res.body.message;
      })
    }
  }
}
</script>
<style lang="css" scoped>
/*1.0 图片分类*/

#cate {
  margin-top: 40px;
  width: 375px;
  max-width: 375px;
  overflow-x: auto;
}

#cate ul {
  margin: 0px;
  padding-left: 10px;
}

#cate li {
  cursor: pointer;
  list-style: none;
  display: inline-block;
  color: #0094ff;
  font-size: 14px;
  padding-left: 6px;
}





/*2.0 实现图片列表样式*/

#imglist ul {
  padding-left: 0px;
}

#imglist li {
  list-style: none;
  position: relative;
}

#imglist img {
  width: 100%;
  height: 300px;
}

#desc {
  width: 100%;
  background-color: rgba(0, 0, 0, 0.2);
  position: absolute;
  bottom: 2px;
  left: 0px;
}

#desc h5 {
  color: #ffffff;
  font-weight: bold;
}

#desc p {
  color: #fff;
}

image[lazy=loading] {
  width: 40px;
  height: 300px;
  margin: auto;
}
</style>